import request from '@/config/axios'

interface parkDataType {
  address: string
  name: string
  area: number
  type: string
  number: number
  rank: string
  time: string
  visitor: number
  objectId?: string
  intro: string
}
interface WhereType {
  name: { $regex: string; $options: 'i' }
  // lv1: string
}
export const Overview = (page: number = 1, size: number = 10, condition?: { name: string }) => {
  const skip = (page - 1) * size
  const where: WhereType = {
    // jobName: { "$regex": "设计", "$options": "i" };
  } as WhereType
  // 携带公园名称
  if (condition && condition.name) {
    where.name = { $regex: condition.name, $options: 'i' }
  }

  const query = JSON.stringify(where)
  return request.get({
    url: `/1.1/classes/ParkInfo?where=${query}&limit=${size}&count=${1}&skip=${skip}`
    // params: {
    //   limit: size,
    //   count: 1, //开启对象计数（数据表总条数）
    //   skip
    // }
  })
}
// 新增
export const parkAdd = (data) => {
  return request.post({ url: '/1.1/classes/ParkInfo', data })
}

// 新增编辑
export const parkPut = (id: string, data: Omit<parkDataType, 'objectId'>) => {
  // 发起put请求
  return request.put({ url: `/1.1/classes/ParkInfo/${id}`, data })
}
// 删除
export const parkDel = (id: string) => {
  return request.delete({ url: `/1.1/classes/ParkInfo/${id}` })
}
// 高德地图
export const parkMap = () => {
  return request.get({ url: `/1.1/classes/ParkInfo` })
}

// 游客监管查询
export const parkVisitor = (condition: { name: string }) => {
  const where: any = {}
  // 携带公园名称
  if (condition && condition.name) {
    where.name = { $regex: condition.name, $options: 'i' }
  }
  const query = JSON.stringify(where)
  return request.get({
    url: `/1.1/classes/ParkInfo?where=${query}`
  })
}
export const getParkItems = (objectId) => {
  return request.get({
    url: `/1.1/classes/ParkInfo/${objectId}`
  })
}
